package com.liaoct.lct.activity;

import com.liaoct.lct.listener.LoginOnClickListener;
import com.liaoct.lct.util.Constant;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupWindow;

/**
 * 登录Activity
 * 
 * @author liaoct
 * 
 */
public class LoginActivity extends BaseActivity {

	private EditText editTextUser;

	private EditText editTextPwd;

	private Button buttonLogin;

	private Button buttonRegister;

	private PopupWindow registerWindow;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		this.init();
	}

	private void init() {
		editTextUser = (EditText) this.findViewById(R.id.editTextUser);
		editTextPwd = (EditText) this.findViewById(R.id.editTextPwd);
		buttonLogin = (Button) this.findViewById(R.id.buttonLogin);
		buttonLogin.setOnClickListener(new LoginOnClickListener(this,
				Constant.BUTTON_LOGIN));
		buttonRegister = (Button) this.findViewById(R.id.buttonRegister);
		buttonRegister.setOnClickListener(new LoginOnClickListener(this,
				Constant.BUTTON_REGISTER));
	}

	@Override
	public void nextActivity() {
		Intent intent = new Intent(this, MainActivity.class);
		this.startActivity(intent);
		this.finish();
	}

	public void login() {
		String userName = editTextUser.getText().toString();
		String passWord = editTextPwd.getText().toString();
		if ("test".equals(userName) && "test".equals(passWord)) {
			nextActivity();
		} else {
		}
	}

	public void register() {
		registerWindow = new PopupWindow(this.getLayoutInflater().inflate(
				R.layout.popupwindow_register, null),
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		registerWindow.showAtLocation(buttonRegister, Gravity.CENTER, 0, 0);
		registerWindow.dismiss();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
